<?php
namespace Home\Controller;

use Common\Controller\HomeController;

class AuthGroupController extends HomeController
{
    /**
     * 角色列表
     * @author Mr.Alien
     * @return string
     */
    public function index($p=1)
    {
        I('get.title') && ($this->where['title'] = array('like','%'.I('get.title').'%'));
        $this->order = '';
        $this->assign('rules',M('AuthRule')->select());
        parent::index($p);
    }

    /**
     * 获取权限情况
     * @author Mr.Alien
     * @return string
     */
    public function getRule($id)
    {
        $info  = M('AuthGroup')->where(array('id'=>(int)$id))->find();
        $this->assign('info',$info);
        $this->assign('rules',M('AuthRule')->select());
        $this->display('rules');
    }

    /**
     * 保存用户权限
     * @author Mr.Alien
     * @return string
     */
    public function saveRight()
    {
        $data = I('post.');
        $res = M("AuthGroup")->where(array('id'=>$data['user_id']))->save(array('rules'=>implode(',',$data['rules'])));
        if($res === false){
            $this->error('保存失败');
        }else{
            $this->success('保存成功');
        }
    }
}